#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   APP_ClearDiagInfo_0x14_test.py
@Time    :   2025/04/07 13:31:28
@Author  :   YangLiang 
@Version :   1.0
@Contact :   yangl@genvict.com
@License :   (C)Copyright 2022-2025
@Desc    :   None
'''

# here put the import lib
from pytest_assume.plugin import assume
import Set_up 
import pytest
import time
import requests
from sympy import I
# from sympy import assuming
from commDriver.TS_CAN import *
import allure
import sys
from collections.abc import Iterable

from sqlalchemy import false
sys.dont_write_bytecode = True

ClearDtcInfo_NRC13 = [
    ("14", "7F 14 13"),
    ("14 FF", "7F 14 13"),
    ("14 FF FF", "7F 14 13"),
    ("14 FF FF FF FF", "7F 14 13"),
    ("14 11 22 FF FF", "7F 14 13"),
]

ClearDtcInfo_NRC31 = [
    ("14 FF FF FE", "7F 14 31"),
    ("14 C1 29 87", "7F 14 31"),
    ("14 5C 11 83", "7F 14 31"),
    ("14 5C 12 83", "7F 14 31"),
    ("14 5C 13 82", "7F 14 31"),
    ("14 5C 14 82", "7F 14 31"),
    ("14 5C 15 81", "7F 14 31"),
    ("14 5C 16 81", "7F 14 31"),
    ("14 C1 01 87", "7F 14 31"),
    ("14 5C 17 83", "7F 14 31"),
    ("14 5C 18 82", "7F 14 31"),
    ("14 5C 19 81", "7F 14 31"),
    ("14 C1 84 87", "7F 14 31"),
    ("14 C1 40 87", "7F 14 31"),
    ("14 5C 1A 81", "7F 14 31"),
    ("14 5C 00 88", "7F 14 31"),
    ("14 5C 01 88", "7F 14 31"),
    ("14 5C 02 87", "7F 14 31"),
    ("14 5C 03 17", "7F 14 31"),
    ("14 5C 04 16", "7F 14 31"),
    ("14 5C 05 17", "7F 14 31"),
    ("14 5C 06 16", "7F 14 31"),
    ("14 5C 07 54", "7F 14 31"),
    ("14 5C 08 54", "7F 14 31"),
    ("14 5C 09 4B", "7F 14 31"),
    ("14 5C 0A 4B", "7F 14 31"),
    ("14 5C 0B 02", "7F 14 31"),
    ("14 5C 0C 02", "7F 14 31"),
    ("14 5C 0D 44", "7F 14 31"),
    ("14 5C 0E 44", "7F 14 31"),
    ("14 5C 0F 4A", "7F 14 31"),
    ("14 5C 10 4A", "7F 14 31"),
    ("14 5C 1B 4A", "7F 14 31"),
    ("14 5C 1C 4A", "7F 14 31")
]


class Test_APP_ClearDiagInfo_Phy(object):
      @allure.severity('normal')
      @allure.title('物理寻址-默认会话-14服务正响应')
      @allure.description('测试物理寻址默认会话下14服务正响应')
      def test_ClearDiagnosticInformation_Default_Phy(self,action,Driver):
         iStep = 1
         iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 1, iStep, False)

      @allure.severity('normal')
      @allure.title('物理寻址-扩展会话-14服务正响应')
      @allure.description('测试物理寻址扩展会话下14服务正响应')
      def test_ClearDiagnosticInformation_Extended_Phy(self,action,Driver):
         iStep = 1
         iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 3, iStep, False)

     
      ids = [f'Request {req}' for req,resp in ClearDtcInfo_NRC13]
      @allure.severity('minor')
      @allure.title('物理寻址-默认会话-14服务NRC13响应')
      @allure.description('测试物理寻址默认会话下14服务NRC13响应')
      @pytest.mark.parametrize('req,resp', ClearDtcInfo_NRC13,ids = ids)
      def test_ClearDiagnosticInformation_NRC13_Default_Phy(self,action,Driver,req,resp):
         iStep = 1
         iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 1, iStep, False)

      ids = [f'Request {req}' for req,resp in ClearDtcInfo_NRC13]
      @allure.severity('minor')
      @allure.title('物理寻址-扩展会话-14服务NRC13响应')
      @allure.description('测试物理寻址扩展会话下14服务NRC13响应')
      @pytest.mark.parametrize('req,resp', ClearDtcInfo_NRC13,ids = ids)
      def test_ClearDiagnosticInformation_NRC13_Extended_Phy(self,action,Driver,req,resp):
         iStep = 1
         iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep, False)

      
      ids = [f'Request {req}' for req,resp in ClearDtcInfo_NRC31]
      @allure.severity('minor')
      @allure.title('物理寻址-默认会话-14服务NRC31响应')
      @allure.description('测试物理寻址默认会话下14服务NRC31响应')
      @pytest.mark.parametrize('req,resp', ClearDtcInfo_NRC31,ids = ids)
      def test_ClearDiagnosticInformation_NRC31_Default_Phy(self,action,Driver,req,resp):
         iStep = 1
         iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 1, iStep, False)

      ids = [f'Request {req}' for req,resp in ClearDtcInfo_NRC31]
      @allure.severity('minor')
      @allure.title('物理寻址-扩展会话-14服务NRC31响应')
      @allure.description('测试物理寻址扩展会话下14服务NRC31响应')
      @pytest.mark.parametrize('req,resp', ClearDtcInfo_NRC31,ids = ids)
      def test_ClearDiagnosticInformation_NRC31_Extended_Phy(self,action,Driver,req,resp):
         iStep = 1
         iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep, False)

      @allure.severity('minor')
      @allure.title('物理寻址-编程会话-14服务NRC11响应')
      @allure.description('测试物理寻址编程会话下14服务NRC11响应')
      def test_ClearDiagInfo_NRC11_Programming_Phy(self,action,Driver):
         time.sleep(0.5)
         iStep = 1
         # boot改的支持14服务了
         iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 2, iStep, False)

      # @allure.severity('normal')
      # @allure.title('物理寻址-默认会话-14服务NRC22响应')
      # @allure.description('测试物理寻址默认会话下14服务NRC22响应')
      # def test_ClearDiagnosticInformation_NRC22_Default_Phy(self, action, Driver):
      #    iStep = 1
      #    iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 0)
      #    time.sleep(1)
      #    iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 0, iStep, False)
      #    iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 10)
      #    time.sleep(1)
      #    iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '7F 14 22', 0, iStep, False)
      #    iStep = Driver['CAN'].SetVehicleSpeedStatus(Driver, iStep, False)
      #    time.sleep(10)
      #    logging.info("Wait 10s")
      #    iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 0, iStep, False)
      #    iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 01', '50 01', 0, iStep, False)
      #    time.sleep(1)
      #    iStep = Driver['CAN'].SetVehicleSpeedStatus(Driver, iStep, True)
      #    iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 0)

      # @allure.severity('normal')
      # @allure.title('物理寻址-扩展会话-14服务NRC22响应')
      # @allure.description('测试物理寻址扩展会话下14服务NRC22响应')
      # def test_ClearDiagnosticInformation_NRC22_Extended_Phy(self, action, Driver):
      #    iStep = 1
      #    iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 0)
      #    time.sleep(1)
      #    iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 3, iStep, False)
      #    iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 10)
      #    time.sleep(1)
      #    iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '7F 14 22', 0, iStep, False)
      #    iStep = Driver['CAN'].SetVehicleSpeedStatus(Driver, iStep, False)
      #    time.sleep(10)
      #    logging.info("Wait 10s")
      #    iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 3, iStep, False)
      #    iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 03', '50 03', 0, iStep, False)
      #    time.sleep(1)
      #    iStep = Driver['CAN'].SetVehicleSpeedStatus(Driver, iStep, True)
      #    iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 0)




class Test_APP_ClearDiagInfo_Func(object):
      @allure.severity('normal')
      @allure.title('功能寻址-默认会话-14服务正响应')
      @allure.description('测试功能寻址默认会话下14服务正响应')
      def test_ClearDiagnosticInformation_Default_Func(self,action,Driver):
         iStep = 1
         iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 1, iStep, False, 'UDSFun', 'noClearFault')

      @allure.severity('normal')
      @allure.title('功能寻址-扩展会话-14服务正响应')
      @allure.description('测试功能寻址扩展会话下14服务正响应')
      def test_ClearDiagnosticInformation_Extended_Func(self,action,Driver):
         iStep = 1
         iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 3, iStep, False, 'UDSFun', 'noClearFault')

      ids = [f'Request {req}' for req,resp in ClearDtcInfo_NRC13]
      @allure.severity('minor')
      @allure.title('功能寻址-默认会话-14服务NRC13响应')
      @allure.description('测试功能寻址默认会话下14服务NRC13响应')
      @pytest.mark.parametrize('req,resp', ClearDtcInfo_NRC13,ids = ids)
      def test_ClearDiagnosticInformation_NRC13_Default_Func(self,action,Driver,req,resp):
         iStep = 1
         iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 1, iStep, False, 'UDSFun', 'noClearFault')

      ids = [f'Request {req}' for req,resp in ClearDtcInfo_NRC13]
      @allure.severity('minor')
      @allure.title('功能寻址-扩展会话-14服务NRC13响应')
      @allure.description('测试功能寻址扩展会话下14服务NRC13响应')
      @pytest.mark.parametrize('req,resp', ClearDtcInfo_NRC13,ids = ids)
      def test_ClearDiagnosticInformation_NRC13_Extended_Func(self,action,Driver,req,resp):
         iStep = 1
         iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep, False, 'UDSFun', 'noClearFault')

      
      ids = [f'Request {req}' for req,resp in ClearDtcInfo_NRC31]
      @allure.severity('minor')
      @allure.title('功能寻址-默认会话-14服务NRC31响应')
      @allure.description('测试功能寻址默认会话下14服务NRC31响应')
      @pytest.mark.parametrize('req,resp', ClearDtcInfo_NRC31,ids = ids)
      def test_ClearDiagnosticInformation_NRC31_Default_Func(self,action,Driver,req,resp):
         iStep = 1
         iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, '', 1, iStep, False, 'UDSFun', 'noClearFault')

      ids = [f'Request {req}' for req,resp in ClearDtcInfo_NRC31]
      @allure.severity('minor')
      @allure.title('功能寻址-扩展会话-14服务NRC31响应')
      @allure.description('测试功能寻址扩展会话下14服务NRC31响应')
      @pytest.mark.parametrize('req,resp', ClearDtcInfo_NRC31,ids = ids)
      def test_ClearDiagnosticInformation_NRC31_Extended_Func(self,action,Driver,req,resp):
         iStep = 1
         iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, '', 3, iStep, False, 'UDSFun', 'noClearFault')

      @allure.severity('minor')
      @allure.title('功能寻址-编程会话-14服务正响应')
      @allure.description('测试功能寻址编程会话下14服务正响应')
      def test_ClearDiagInfo_Programming_Func(self,action,Driver):
         time.sleep(0.5)
         iStep = 1
         iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 2, iStep, False, 'UDSFun', 'noClearFault')

      # @allure.severity('normal')
      # @allure.title('功能寻址-默认会话-14服务NRC22响应')
      # @allure.description('测试功能寻址默认会话下14服务NRC22响应')
      # def test_ClearDiagnosticInformation_NRC22_Default_Func(self, action, Driver):
      #    iStep = 1
      #    iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 0)
      #    time.sleep(1)
      #    iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 0, iStep, False, 'UDSFun', 'noClearFault')
      #    iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 10)
      #    time.sleep(1)
      #    iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '7F 14 22', 0, iStep, False, 'UDSFun', 'noClearFault')
      #    iStep = Driver['CAN'].SetVehicleSpeedStatus(Driver, iStep, False)
      #    time.sleep(10)
      #    logging.info("Wait 10s")
      #    iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 0, iStep, False, 'UDSFun', 'noClearFault')
      #    iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 01', '50 01 00 32 01 F4', 0, iStep, False, 'UDSFun', 'noClearFault')
      #    time.sleep(1)
      #    iStep = Driver['CAN'].SetVehicleSpeedStatus(Driver, iStep, True)
      #    iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 0)

      # @allure.severity('normal')
      # @allure.title('功能寻址-扩展会话-14服务NRC22响应')
      # @allure.description('测试功能寻址扩展会话下14服务NRC22响应')
      # def test_ClearDiagnosticInformation_NRC22_Extended_Func(self, action, Driver):
      #    iStep = 1
      #    iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 0)
      #    time.sleep(1)
      #    iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 3, iStep, False, 'UDSFun', 'noClearFault')
      #    iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 10)
      #    time.sleep(1)
      #    iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '7F 14 22', 0, iStep, False, 'UDSFun', 'noClearFault')
      #    iStep = Driver['CAN'].SetVehicleSpeedStatus(Driver, iStep, False)
      #    time.sleep(10)
      #    logging.info("Wait 10s")
      #    iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 3, iStep, False, 'UDSFun', 'noClearFault')
      #    iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 03', '50 03 00 32 01 F4', 0, iStep, False, 'UDSFun', 'noClearFault')
      #    time.sleep(1)
      #    iStep = Driver['CAN'].SetVehicleSpeedStatus(Driver, iStep, True)
      #    iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 0)
     